// import * as Updates from "expo-updates";
import { Platform } from "react-native";
import { createSlice } from "@reduxjs/toolkit";
import type { PayloadAction } from "@reduxjs/toolkit";
import type { ThemeMode } from "@/constants/Themes";

export interface ThemeState {
  theme: ThemeMode;
}

const initialState: ThemeState = {
  theme: "light",
};

export const themeSlice = createSlice({
  name: "theme",
  initialState,
  reducers: {
    setTheme: (state, action: PayloadAction<ThemeMode>) => {
      state.theme = action.payload;
      // // 然后重启应用
      // if (Platform.OS === "web") {
      //   window.location.reload();
      // } else {
      //   // Updates.reloadAsync().catch(console.error);
      // }
    },
  },
});

export const { setTheme } = themeSlice.actions;
export default themeSlice.reducer;
